$(document).ready(function () {

    $('title').html("注册");
    $('.modal-footer .btn-primary').html('已阅读');
    var av = new AccountValidator();

    // $('#account-form').ajaxForm({
    //
    //     url: 'signup',
    //     type: 'post',
    //
    //     // beforeSerialize : function() {}
    //     //提交前验证
    //     beforeSubmit: function (formData, jqForm, options) {
    //
    //         // console.log('- user-name- : ' + $('#user-name').val());
    //         // console.log('- user-name- : ' + $('#code-upload-image').attr('src'));
    //
    //         // formData.push({name: 'user', value: $('#user-name').val()});
    //         // formData.push({name: 'pass', value: $('#pass-tf').val()});
    //         // formData.push({name: 'business-license', value: 'fsfasdfa'});
    //         // formData.push({name: 'organization-code', value: 'organization-code'});
    //         // formData.push({name: 'organization-code', value: $('#code-upload-image').attr('src')});
    //         return av.validateForm();
    //     },
    //     data: getUserData(),
    //     //提交成功
    //     success: function (result) {
    //         if (result['code'] == 1) {
    //             generateNotify('', result['msg'], 'success');
    //         }
    //         else {
    //             generateNotify('', result['msg'], 'danger');
    //         }
    //     }
    //
    // });


    //
    $('#account-form-btn2').click(function () {
        if (av.validateForm('add')) { //验证成功
            var userData = av.getUserData();
            $.post('/signup', userData, function (result) {
                if (result['id'] == 1) { //成功
                    generateNotify('', result.msg, 'success');
                    //回到首页
                    var loginUrl = '/?user=' + userData['user'];
                    console.log('--- loginUrl --- ', loginUrl);
                    setTimeout(function () {
                        $(location).attr('href', loginUrl);
                    }, 500);
                } else { //失败
                    generateNotify('', result.msg, 'danger');
                }
            });
        }

    });

    //取消
    $('#account-form-btn1').click(function () {
        $(location).attr('href', '/');
    });

    $('#name-user').focus();

    $('#protocol').click(function () {
        bootbox.alert({
            size: "small",
            title: "会议室使用须知",
            message: protocolMsg,
        });
        $('.modal-footer .btn')[4].innerText = '同意';
    });

    $('#protocolPrivacy').click(function () {
        bootbox.alert({
            size: "small",
            title: "违章处罚条例",
            message: protocolMsg,

        });
        $('.modal-footer .btn')[4].innerText = '同意';
    });

    $('#account-form-btn2').addClass('btn-primary');

// setup the alert that displays when an account is successfully created //
    $('.modal-alert').modal({show: false, keyboard: false, backdrop: 'static'});
    $('.modal-alert .modal-header h4').text('Account Created!');
    $('.modal-alert .modal-body p').html('Your account has been created.</br>Click OK to return to the login page.');
});


